// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav:0,
    navtype:false,
    search:'',
    searchLength:0,
    searchList:[],
    searchshow_hide:false,
    goodList:[],
    typeList:[],
    goodshow_hide:false,
    zhezhaoshow_hide:false,
    typeshow_hide:0,
    animation:'',
    page:1,
    scroll:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goodList: [{img: '../../../asset/image/groom1.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
      { img: '../../../asset/image/groom1.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
      { img: '../../../asset/image/groom1.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
      { img: '../../../asset/image/groom1.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' }
      ],
      typeList: [{ id: 0, typename: '上衣'},
        { id: 1, typename: '裤子' },
        { id: 2, typename: '外套'},
        { id: 3, typename: '短裙'}
      ]
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var animation = wx.createAnimation({
      duration: 400,
      timingFunction: "ease",
      delay: 0
    })
    this.setData({
      animation: animation.export()
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  searchSubmit:function(event){
    var data = this.data;
    var newarray = [data.search], length = data.search.length;
    var searchList = newarray.concat(data.searchList)
    if (length>0){
      this.setData({
        nav:0,
        searchshow_hide: false,
        goodshow_hide:true,
        searchList: searchList,
        searchLength:length
      })
    }
    
  },
  inputblur:function(event){
    var value = event.detail.value,data = this.data
    if (value.length < data.searchLength){
      this.setData({
        searchshow_hide: true,
        goodshow_hide: false
      })
    }
    this.setData({
      search: value      
    })
  },
  clearHistory:function(){
    this.setData({
      searchList: [],
      searchshow_hide: false,
      searchLength:0
    })
  },
  navChange:function(event){
    var val = event.currentTarget.id, imgid = parseInt(val)+1
    this.setData({
      nav:val,
      goodList: [{ img: '../../../asset/image/groom' + imgid+'.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
        { img: '../../../asset/image/groom' + imgid +'.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
        { img: '../../../asset/image/groom' + imgid +'.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
        { img: '../../../asset/image/groom' + imgid +'.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' }
      ]
    })
  },
  viewHide:function(){
    this.animation.translateX('50vw').step()
    this.setData({
      zhezhaoshow_hide:false,
      animation: this.animation.export()
    })
  },
  navChoose:function(event){
    var animation = wx.createAnimation({
      duration: 400,
      timingFunction: "ease",
      delay: 0
    }) 
    this.animation = animation

    animation.translateX('0vw').step()
    this.setData({
      navtype:true,
      animation: animation.export(),
      zhezhaoshow_hide: true
    })
  },
  typeChoose: function (event){
    var val = event.currentTarget.id
    this.setData({
      typeshow_hide: val,
    })
  }, 
  ajaxMore:function(e){
    var _this = this
    var good = [{ img: '../../../asset/image/groom1.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
      { img: '../../../asset/image/groom2.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
      { img: '../../../asset/image/groom3.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' },
      { img: '../../../asset/image/groom1.jpg', goodname: '入夏套装新品', goodprice: '30.00', sellnum: '2500' }
    ]
    var goodList = this.data.goodList .concat(good);
    this.setData({
      page: ++this.data.page,
      goodList: goodList,
      scroll:false
    })
    console.log(this.data.page)
    wx.showLoading({
        title: '加载中...',
        mask: true,
        success: function(){
          _this.setData({
            scroll: true
          })
          wx.hideLoading()
        }
    })
    
  }
})